<?php
// +----------------------------------------------------------------------
// | @filename MenuRepository.php
// +----------------------------------------------------------------------
// | @author 落花轻舞问君愁 <mwcx1990@qq.com>
// +----------------------------------------------------------------------
// | @datetime 2021-11-01 17:58:06
// +----------------------------------------------------------------------
// | @Description
// +----------------------------------------------------------------------

namespace Addons\Backend\Repositories;


use Addons\Backend\Models\Menu;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;

class MenuRepository extends BaseRepository
{
    protected $model;

    public function __construct(Menu $menu)
    {
        $this->model = $menu;
    }

    /**
     * 根据sort升序获取所有菜单
     * @return Builder[]|Collection
     */
    public function orderBySortAll()
    {
        return $this->model::query()
            ->with(['roles:id'])
            ->orderBy('sort', 'ASC')
            ->orderBy('id', 'ASC')
            ->get();
    }

    /**
     * 获取下级菜单
     * @param $pid
     * @return Builder[]|Collection
     */
    public function getChildrenByPid($pid){
        return $this->model::query()->where('pid',$pid)->get();
    }


}
